package com.gwc.intervaltree;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Set;

public class TestIntervalTree {
    public static void main(String[] args) throws ParseException {
        IntervalTree<Date> tree = new IntervalTree<>();
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date d1 = df.parse("2021-07-24 18:13:54");
        Date d2 = df.parse("2021-07-24 18:19:33");
        Date d3 = df.parse("2021-07-24 19:49:12");
        Date d4 = df.parse("2021-07-24 19:56:41");
        tree.add(new DateInterval(d1, d2, Interval.Bounded.CLOSED, "1"));
        tree.add(new DateInterval(d3, d4, Interval.Bounded.CLOSED, "2"));

        Date d5 = df.parse("2021-07-24 18:10:00");
        Date d6 = df.parse("2021-07-24 19:55:00");
        Set<Interval<Date>> result = tree.query(new DateInterval(d5, d6, Interval.Bounded.CLOSED, "3"));
        for (Interval<Date> date : result) {
            System.out.println(date.getStart() + "--" + date.getEnd());
        }
    }
}
